home *** CD-ROM | disk | FTP | other *** search
- package tetris;
-
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.CommandListener;
- import javax.microedition.lcdui.Display;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.lcdui.Form;
- import javax.microedition.lcdui.Image;
- import javax.microedition.lcdui.List;
-
- public class MainMenu extends List implements CommandListener {
- static byte continueMenuItemNr = 6;
- boolean savedGame = false;
-
- public MainMenu() {
- super("HTetris", 3);
-
- try {
- this.jbInit();
- } catch (Exception e) {
- ((Throwable)e).printStackTrace();
- }
-
- }
-
- private void jbInit() throws Exception {
- ((Displayable)this).setCommandListener(this);
- ((Displayable)this).addCommand(new Command("Exit", 7, 1));
- ((List)this).append("New game", (Image)null);
- ((List)this).append("High scores", (Image)null);
- ((List)this).append("Options", (Image)null);
- ((List)this).append("Redefine keys", (Image)null);
- ((List)this).append("Help", (Image)null);
- ((List)this).append("About", (Image)null);
- if (GameScreen.existsSavedGame()) {
- this.savedGame = true;
- this.addContinue();
- }
-
- }
-
- public void addContinue() {
- ((List)this).append("Continue", (Image)null);
- ((List)this).setSelectedIndex(continueMenuItemNr, true);
- }
-
- public void redefineKeys(Displayable d) {
- Options.optDefaultKeys = false;
- Options.opt2.setSelectedIndex(0, false);
- Options.openStore();
- Options.saveOptions();
- Options.closeStore();
- Display.getDisplay(TetrisMIDlet.instance).setCurrent(new GetKey(d));
- }
-
- public void commandAction(Command command, Displayable displayable) {
- if (command.getCommandType() == 7) {
- TetrisMIDlet.quitApp();
- }
-
- if (command.getCommandType() == 2) {
- Display.getDisplay(TetrisMIDlet.instance).setCurrent(this);
- }
-
- if (command == List.SELECT_COMMAND) {
- switch (((List)this).getSelectedIndex()) {
- case 0:
- if (((List)this).size() > continueMenuItemNr) {
- ((List)this).delete(continueMenuItemNr);
- ((List)this).setSelectedIndex(0, true);
- }
-
- Display.getDisplay(TetrisMIDlet.instance).setCurrent(TetrisMIDlet.gameScreen);
- TetrisMIDlet.gameScreen.startGame();
- break;
- case 1:
- TetrisMIDlet.highScores.updateScores();
- Display.getDisplay(TetrisMIDlet.instance).setCurrent(TetrisMIDlet.highScores);
- break;
- case 2:
- Display.getDisplay(TetrisMIDlet.instance).setCurrent(TetrisMIDlet.options);
- break;
- case 3:
- this.redefineKeys(this);
- break;
- case 4:
- Form help = new Form("Help");
- help.append("This is a classic tetris game. Your aim is to put the falling blocks in the way they form full rows, which will dissappear.");
- help.append("\n\n".concat(String.valueOf(String.valueOf(Options.currentKeys(true)))));
- ((Displayable)help).setCommandListener(this);
- ((Displayable)help).addCommand(new Command("Back", 2, 1));
- Display.getDisplay(TetrisMIDlet.instance).setCurrent(help);
- break;
- case 5:
- Form about = new Form("About");
- String x = TetrisMIDlet.instance.getAppProperty("MIDlet-Version");
- about.append("HTetris ".concat(String.valueOf(String.valueOf(x == null ? "" : x))));
- about.append("\n(c) 2002\nCopyrights by\nCsomos Tamas");
- ((Displayable)about).setCommandListener(this);
- ((Displayable)about).addCommand(new Command("Back", 2, 1));
- Display.getDisplay(TetrisMIDlet.instance).setCurrent(about);
- break;
- case 6:
- ((List)this).delete(continueMenuItemNr);
- ((List)this).setSelectedIndex(0, true);
- if (!this.savedGame || TetrisMIDlet.gameScreen.loadGame()) {
- this.savedGame = false;
- Display.getDisplay(TetrisMIDlet.instance).setCurrent(TetrisMIDlet.gameScreen);
- TetrisMIDlet.gameScreen.resumeGame();
- }
- }
- }
-
- }
- }
-